﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Data.SqlTypes;

namespace DataAccess.Operate
{
    public class DA_Project_EarlyPlot_Operate:SqlInteractionBase
    {

        private DataEntity.T_Project_EarlyPlot _objMessage = null;

        public override bool Insert(object obj)
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Project_EarlyPlot_Insert]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;
            this._objMessage = (DataEntity.T_Project_EarlyPlot)obj;
            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_EarlyPlot_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_ID));
                cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_EarlyPlot_MainID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_MainID));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstA1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstA1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_FirstA2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstA2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstA3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstA3));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstB1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstB1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_FirstB2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstB2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstB3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstB3));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstC1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstC1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_FirstC2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstC2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstC3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstC3));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstD1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstD1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_FirstD2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstD2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstD3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstD3));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstE1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstE1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_FirstE2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstE2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstE3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_FirstE3));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_Second1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_Second1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_Second2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_Second2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_Second3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, this._objMessage.Project_EarlyPlot_Second3));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcProject_EarlyPlot_Fees", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_Fees));
                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                _rowsAffected = cmdToExecute.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Project_EarlyPlot::Insert::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
            }
        }


        public override object SelectOne(object obj)
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Project_EarlyPlot_SelectOne]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;
            DataTable toReturn = new DataTable("t_Project_EarlyPlot");
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;
            this._objMessage = new DataEntity.T_Project_EarlyPlot();
            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_EarlyPlot_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, SqlGuid.Parse(obj.ToString())));

                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                adapter.Fill(toReturn);
                if (toReturn.Rows.Count > 0)
                {
                    _objMessage.Project_EarlyPlot_ID = (Guid)toReturn.Rows[0]["Project_EarlyPlot_ID"];
                    _objMessage.Project_EarlyPlot_MainID = (Guid)toReturn.Rows[0]["Project_EarlyPlot_MainID"];
                    _objMessage.Project_EarlyPlot_FirstA1 = toReturn.Rows[0]["Project_EarlyPlot_FirstA1"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_FirstA1"];
                    _objMessage.Project_EarlyPlot_FirstA2 = toReturn.Rows[0]["Project_EarlyPlot_FirstA2"] == System.DBNull.Value ? SqlInt32.Null : (Int32)toReturn.Rows[0]["Project_EarlyPlot_FirstA2"];
                    _objMessage.Project_EarlyPlot_FirstA3 = toReturn.Rows[0]["Project_EarlyPlot_FirstA3"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_FirstA3"];
                    _objMessage.Project_EarlyPlot_FirstB1 = toReturn.Rows[0]["Project_EarlyPlot_FirstB1"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_FirstB1"];
                    _objMessage.Project_EarlyPlot_FirstB2 = toReturn.Rows[0]["Project_EarlyPlot_FirstB2"] == System.DBNull.Value ? SqlInt32.Null : (Int32)toReturn.Rows[0]["Project_EarlyPlot_FirstB2"];
                    _objMessage.Project_EarlyPlot_FirstB3 = toReturn.Rows[0]["Project_EarlyPlot_FirstB3"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_FirstB3"];
                    _objMessage.Project_EarlyPlot_FirstC1 = toReturn.Rows[0]["Project_EarlyPlot_FirstC1"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_FirstC1"];
                    _objMessage.Project_EarlyPlot_FirstC2 = toReturn.Rows[0]["Project_EarlyPlot_FirstC2"] == System.DBNull.Value ? SqlInt32.Null : (Int32)toReturn.Rows[0]["Project_EarlyPlot_FirstC2"];
                    _objMessage.Project_EarlyPlot_FirstC3 = toReturn.Rows[0]["Project_EarlyPlot_FirstC3"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_FirstC3"];
                    _objMessage.Project_EarlyPlot_FirstD1 = toReturn.Rows[0]["Project_EarlyPlot_FirstD1"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_FirstD1"];
                    _objMessage.Project_EarlyPlot_FirstD2 = toReturn.Rows[0]["Project_EarlyPlot_FirstD2"] == System.DBNull.Value ? SqlInt32.Null : (Int32)toReturn.Rows[0]["Project_EarlyPlot_FirstD2"];
                    _objMessage.Project_EarlyPlot_FirstD3 = toReturn.Rows[0]["Project_EarlyPlot_FirstD3"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_FirstD3"];
                    _objMessage.Project_EarlyPlot_FirstE1 = toReturn.Rows[0]["Project_EarlyPlot_FirstE1"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_FirstE1"];
                    _objMessage.Project_EarlyPlot_FirstE2 = toReturn.Rows[0]["Project_EarlyPlot_FirstE2"] == System.DBNull.Value ? SqlInt32.Null : (Int32)toReturn.Rows[0]["Project_EarlyPlot_FirstE2"];
                    _objMessage.Project_EarlyPlot_FirstE3 = toReturn.Rows[0]["Project_EarlyPlot_FirstE3"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_FirstE3"];
                    _objMessage.Project_EarlyPlot_Second1 = toReturn.Rows[0]["Project_EarlyPlot_Second1"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_Second1"];
                    _objMessage.Project_EarlyPlot_Second2 = toReturn.Rows[0]["Project_EarlyPlot_Second2"] == System.DBNull.Value ? SqlInt32.Null : (Int32)toReturn.Rows[0]["Project_EarlyPlot_Second2"];
                    _objMessage.Project_EarlyPlot_Second3 = toReturn.Rows[0]["Project_EarlyPlot_Second3"] == System.DBNull.Value ? SqlString.Null : (string)toReturn.Rows[0]["Project_EarlyPlot_Second3"];
                    _objMessage.Project_EarlyPlot_Fees = toReturn.Rows[0]["Project_EarlyPlot_Fees"] == System.DBNull.Value ? SqlDecimal.Null : (Decimal)toReturn.Rows[0]["Project_EarlyPlot_Fees"];
                }
                return this._objMessage;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Project_EarlyPlot::SelectOne::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
                adapter.Dispose();
            }
        }

        public override bool Update(object obj)
        {
            SqlCommand cmdToExecute = new SqlCommand();
            cmdToExecute.CommandText = "dbo.[sp_t_Project_EarlyPlot_Update]";
            cmdToExecute.CommandType = CommandType.StoredProcedure;

            // Use base class' connection object
            cmdToExecute.Connection = _mainConnection;
            this._objMessage = (DataEntity.T_Project_EarlyPlot)obj;
            try
            {
                cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_EarlyPlot_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_ID));
                cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_EarlyPlot_MainID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_MainID));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstA1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstA1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_FirstA2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstA2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstA3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstA3));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstB1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstB1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_FirstB2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstB2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstB3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstB3));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstC1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstC1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_FirstC2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstC2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstC3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstC3));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstD1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstD1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_FirstD2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstD2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstD3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstD3));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstE1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstE1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_FirstE2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstE2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_FirstE3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_FirstE3));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_Second1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_Second1));
                cmdToExecute.Parameters.Add(new SqlParameter("@iProject_EarlyPlot_Second2", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_Second2));
                cmdToExecute.Parameters.Add(new SqlParameter("@sProject_EarlyPlot_Second3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_Second3));
                cmdToExecute.Parameters.Add(new SqlParameter("@dcProject_EarlyPlot_Fees", SqlDbType.Decimal, 9, ParameterDirection.Input, false, 18, 1, "", DataRowVersion.Proposed, _objMessage.Project_EarlyPlot_Fees));
                if (_mainConnectionIsCreatedLocal)
                {
                    // Open connection.
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                // Execute query.
                _rowsAffected = cmdToExecute.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                // some error occured. Bubble it to caller and encapsulate Exception object
                throw new Exception("T_Project_EarlyPlot::Update::Error occured.", ex);
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    // Close connection.
                    _mainConnection.Close();
                }
                cmdToExecute.Dispose();
            }
        }

    }
}
